package EBM.UI;
import java.io.IOException;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

import EBM.BLL.SocketConnection;
import EBM.BLL.Util;

public class CommonUser extends org.eclipse.swt.widgets.Composite {
	public static Tree tree1;
	private TreeItem treeItem121;
	private TreeItem treeItem113;
	private TreeItem treeItem112;
	private TreeItem treeItem111;
	private TreeItem treeItem11;
	private TreeItem treeItem12;
	private TreeItem treeItem1;
	private Label lblOldPwd;
	private Label lblNewPwd;
	private Label lblNewPwd2;
	private Button btnSubmitPwd;
	private Button btnResetPwd;
	private Text txtOldPwd;
	private Text txtNewPwd;
	private Text txtNewPwd2;
	private Composite cptPwdModify;
	private Label lblBugId;
	private Text txtBugId;
	private Label lblSubmit;
	private Text txtSubmit;
	private Label lblTime;
	private Text txtTime;
	private Label lblProId;
	private Combo cboProId;
	private Label lblProVersion;
	private Combo cboProVersion;
	private Text txtRecurStep;
	private Text txtBugDetail;
	private TreeItem treeItem2;
	private Combo cboPro;
	private Label lblSubsys;
	private Combo cboSubsys;
	private Label lblHard;
	private Text txtHard;
	private Label lblSoft;
	private Text txtSoft;
	private Label lblSeverity;
	private Combo cboSeverity;
	private Label lblBugSummary;
	private Text txtBugSummary;
	private Label lblRecur;
	private Combo cboRecur;
	private Label lblBugDetail;
	private Label lblRecurStep;
	private Text txtAttach;
	private Label lblAttach;
	private Label lblNext;
	private Button btnAssignReview;
	private Button btnClose;
	private Combo cboAssignReview;
	private Combo cboClose;
	private Button btnSaveBug;
	private Button btnSubmitBug;

	public static String userName;
	public static Display display;
	public static Shell shell;
	private Label lblPro;
	private TableColumn tableColumn1;
	private TableColumn tableColumn2;
	private TableColumn tableColumn3;
	private TableColumn tableColumn4;
	private TableColumn tableColumn6;
	private TableColumn tableColumn5;
	private Table table1;
	private Composite cptPro;
	private Composite composite3;

	private MessageBox box = new MessageBox(shell, SWT.YES | SWT.ICON_WARNING);
	private MessageBox box1 = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
	
	private ArrayList<String> addBugReportProjectId = new ArrayList<String>();
	private ArrayList<String> addBugReportProjectName = new ArrayList<String>();
	
	private ArrayList<String> addBugReportUserId = new ArrayList<String>();
	private ArrayList<String> addBugReportUserName = new ArrayList<String>();
	
	private ArrayList<String> getProjectByUserIdProjectId = new ArrayList<String>();
	private ArrayList<String> getProjectByUserIdProjectName = new ArrayList<String>();
	
	private Group composite3Group1,composite3Group2,composite3Group3,composite3Group4;
	private Group composite1Group;
	
	
	/**
	 * Auto-generated main method to display this 
	 * org.eclipse.swt.widgets.Composite inside a new Shell.
	 */
	/*public static void main(String[] args) {
		showGUI();
	}*/

	/**
	 * Auto-generated method to display this 
	 * org.eclipse.swt.widgets.Composite inside a new Shell.
	 */
	public static void showGUI() {
		display = Display.getDefault();
		shell = new Shell(display, SWT.CLOSE | SWT.MIN);
		CommonUser inst = new CommonUser(shell, SWT.NULL);
		Point size = inst.getSize();
		shell.setLayout(new FillLayout());
		shell.layout();
		shell.setText("普通用户主界面");
		if(size.x == 0 && size.y == 0) {
			shell.pack();
		} else {
			Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
			shell.setSize(shellBounds.width, shellBounds.height);
		}
		shell.setLocation(display.getClientArea().width / 2 - shell.getSize().x/2, 
				display.getClientArea().height / 2 - shell.getSize().y/2);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	public CommonUser(org.eclipse.swt.widgets.Composite parent, int style) {
		super(parent, style);
		initGUI();
		TreeVisible(2);
		InitProjectByUserId();
		InitBugByProject();
	}

	private void initGUI() {
		try {
			this.setLayout(new FormLayout());
			this.setSize(726, 475);
			{
				composite3 = new Composite(this, SWT.NONE);
				FormData composite3LData = new FormData();
				composite3LData.width = 520;
				composite3LData.height = 505;
				composite3LData.left =  new FormAttachment(216, 1000, 0);
				composite3LData.top =  new FormAttachment(0, 1000, 0);
				composite3LData.bottom =  new FormAttachment(1000, 1000, 0);
				composite3LData.right =  new FormAttachment(1000, 1000, 0);
				composite3.setLayoutData(composite3LData);
				composite3.setLayout(null);
				
				composite3Group1 = new Group(composite3,SWT.NONE);
				composite3Group2 = new Group(composite3,SWT.NONE);
				composite3Group3 = new Group(composite3,SWT.NONE);
				composite3Group4 = new Group(composite3,SWT.NONE);
				
				composite3Group1.setBounds(20, 25, 476, 98);
				composite3Group2.setBounds(20, 120, 476, 130);
				composite3Group3.setBounds(20, 244, 475, 120);
				composite3Group4.setBounds(20, 390, 400, 83);
				{
					lblBugId = new Label(composite3, SWT.NONE);
					lblBugId.setText("缺陷报告单ID");
					lblBugId.setBounds(20, 10, 76, 23);
				}
				{
					txtBugId = new Text(composite3, SWT.NONE);
					txtBugId.setBounds(114, 10, 60, 19);
					txtBugId.setEditable(false);
				}
				{
					lblSubmit = new Label(composite3, SWT.NONE);
					lblSubmit.setText("提交人");
					lblSubmit.setBounds(205, 10, 58, 17);
				}
				{
					txtSubmit = new Text(composite3, SWT.NONE);
					txtSubmit.setBounds(269, 10, 60, 17);
					txtSubmit.setEditable(false);
				}
				{
					lblTime = new Label(composite3, SWT.NONE);
					lblTime.setText("提交时间");
					lblTime.setBounds(360, 10, 60, 17);
				}
				{
					txtTime = new Text(composite3, SWT.NONE);
					txtTime.setBounds(426, 10, 59, 17);
					txtTime.setEditable(false);
				}
				{
					lblProId = new Label(composite3Group1, SWT.NONE);
					lblProId.setText("项目编号");
					lblProId.setBounds(25, 20, 50, 20);
				}
				{
					cboProId = new Combo(composite3Group1, SWT.READ_ONLY);
					cboProId.setBounds(85, 15, 94, 23);
					cboProId.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							cboProIdWidgetSelected(evt);
						}
					});
				}
				{
					lblProVersion = new Label(composite3Group1, SWT.NONE);
					lblProVersion.setText("版本");
					lblProVersion.setBounds(185, 20, 29, 22);
				}
				{
					cboProVersion = new Combo(composite3Group1, SWT.READ_ONLY);
					cboProVersion.setBounds(225, 15, 67, 19);
				}
				{
					lblSubsys = new Label(composite3Group1, SWT.NONE);
					lblSubsys.setText("子系统");
					lblSubsys.setBounds(305, 20, 37, 23);
				}
				{
					cboSubsys = new Combo(composite3Group1, SWT.READ_ONLY);
					cboSubsys.setBounds(350, 15, 109, 19);
				}
				{
					lblHard = new Label(composite3Group1, SWT.NONE);
					lblHard.setText("硬件环境");
					lblHard.setBounds(25, 45, 55, 21);
				}
				{
					txtHard = new Text(composite3Group1, SWT.BORDER);
					txtHard.setBounds(85, 45, 129, 22);
				}
				{
					lblSoft = new Label(composite3Group1, SWT.NONE);
					lblSoft.setText("软件环境");
					lblSoft.setBounds(247, 50, 59, 23);
				}
				{
					txtSoft = new Text(composite3Group1, SWT.BORDER);
					txtSoft.setBounds(312, 50, 147, 21);
				}
				{
					lblSeverity = new Label(composite3Group1, SWT.NONE);
					lblSeverity.setText("严重程度");
					lblSeverity.setBounds(25, 70, 56, 20);
				}
				{
					cboSeverity = new Combo(composite3Group1, SWT.READ_ONLY);
					String[] items = {"致命","严重","一般","提示"};
					cboSeverity.setItems(items);
					cboSeverity.select(3);
					cboSeverity.setBounds(87, 70, 77, 22);
				}
				{
					lblBugSummary = new Label(composite3Group2, SWT.NONE);
					lblBugSummary.setText("缺陷概要描述");
					lblBugSummary.setBounds(25, 20, 77, 20);
				}
				{
					txtBugSummary = new Text(composite3Group2, SWT.BORDER);
					txtBugSummary.setBounds(108, 18, 358, 22);
				}
				{
					lblRecur = new Label(composite3Group3, SWT.NONE);
					lblRecur.setText("是否重现");
					lblRecur.setBounds(25, 15, 55, 24);
				}
				{
					cboRecur = new Combo(composite3Group3, SWT.READ_ONLY);
					String[] items = {"是","否"};
					cboRecur.setItems(items);
					cboRecur.select(0);
					cboRecur.setBounds(110, 15, 59, 18);
					cboRecur.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							if(cboRecur.getSelectionIndex() == 0)
								txtRecurStep.setEditable(true);
							else if(cboRecur.getSelectionIndex() == 1){
								txtRecurStep.setText("");
								txtRecurStep.setEditable(false);
							}
						}
					});
				}
				{
					lblBugDetail = new Label(composite3Group2, SWT.NONE);
					lblBugDetail.setText("缺陷详细描述");
					lblBugDetail.setBounds(25, 40, 73, 16);
				}
				{
					lblRecurStep = new Label(composite3Group3, SWT.NONE);
					lblRecurStep.setText("重现步骤");
					lblRecurStep.setBounds(25, 45, 55, 20);
				}
				{
					lblAttach = new Label(composite3, SWT.NONE);
					lblAttach.setText("附件");
					lblAttach.setBounds(45, 368, 53, 23);
				}
				{
					lblNext = new Label(composite3Group4, SWT.NONE);
					lblNext.setText("指定下一步处理");
					lblNext.setBounds(26, 20, 92, 21);
				}
				{
					btnAssignReview = new Button(composite3Group4, SWT.RADIO | SWT.LEFT);
					btnAssignReview.setText("指定审核人");
					btnAssignReview.setBounds(132, 20, 78, 22);
					btnAssignReview.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							cboAssignReview.setEnabled(true);
							cboClose.setEnabled(false);
						}
					});
				}
				{
					btnClose = new Button(composite3Group4, SWT.RADIO | SWT.LEFT);
					btnClose.setText("关闭");
					btnClose.setBounds(132, 50, 51, 22);
					btnClose.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							cboAssignReview.setEnabled(false);
							cboClose.setEnabled(true);
						}
					});
				}
				{
					cboAssignReview = new Combo(composite3Group4, SWT.READ_ONLY);
					cboAssignReview.setBounds(255, 20, 92, 20);
				}
				{
					cboClose = new Combo(composite3Group4, SWT.READ_ONLY);
					String[] items = {"正常","重复","拒绝","无效"};
					cboClose.setItems(items);
					cboClose.select(0);
					cboClose.setBounds(210, 50, 137, 18);
				}
				{
					btnSaveBug = new Button(composite3, SWT.PUSH | SWT.CENTER);
					btnSaveBug.setText("保存");
					btnSaveBug.setBounds(430, 410, 61, 23);
					btnSaveBug.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							btnSaveBugWidgetSelected(evt);
						}
					});
				}
				{
					btnSubmitBug = new Button(composite3, SWT.PUSH | SWT.CENTER);
					btnSubmitBug.setText("提交");
					btnSubmitBug.setBounds(430, 445, 61, 23);
					btnSubmitBug.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							btnSubmitBugWidgetSelected(evt);
						}
					});
				}
				{
					txtBugDetail = new Text(composite3Group2, SWT.WRAP | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER);
					txtBugDetail.setBounds(108, 45, 358, 80);
				}
				{
					txtRecurStep = new Text(composite3Group3, SWT.WRAP | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER);
					txtRecurStep.setBounds(110, 50, 355, 65);
				}
				{
					txtAttach = new Text(composite3, SWT.MULTI | SWT.WRAP | SWT.BORDER);
					txtAttach.setBounds(131, 368,354, 23);
				}
			}
			{
				FormData fd_cptPro = new FormData();
				fd_cptPro.width = 520;
				fd_cptPro.height = 505;
				fd_cptPro.left =  new FormAttachment(216, 1000, 0);
				fd_cptPro.top =  new FormAttachment(0, 1000, 0);
				fd_cptPro.bottom =  new FormAttachment(1000, 1000, 0);
				fd_cptPro.right =  new FormAttachment(1000, 1000, 0);
				cptPro = new Composite(this, SWT.NONE);
				cptPro.setLayout(null);
				cptPro.setLayoutData(fd_cptPro);
				cptPro.setVisible(true);
				cptPro.setEnabled(true);
				{
					table1 = new Table(cptPro, SWT.MULTI);
					table1.setBounds(0, 71, 520, 434);
					
					tableColumn1 = new TableColumn(table1, SWT.CENTER);
				    tableColumn2 = new TableColumn(table1, SWT.CENTER);
				    tableColumn3 = new TableColumn(table1, SWT.CENTER);
				    tableColumn4 = new TableColumn(table1, SWT.CENTER);
				    tableColumn5 = new TableColumn(table1, SWT.CENTER);
				    tableColumn6 = new TableColumn(table1, SWT.CENTER);
				    tableColumn1.setText("");
				    tableColumn2.setText("问题单号");
				    tableColumn3.setText("当前责任人");
				    tableColumn4.setText("当前状态");
				    tableColumn5.setText("问题概要描述");
				    tableColumn6.setText("停留天数");
				    tableColumn1.setWidth(18);
				    tableColumn2.setWidth(80);
				    tableColumn3.setWidth(80);
				    tableColumn4.setWidth(80);
				    tableColumn5.setWidth(150);
				    tableColumn6.setWidth(70);
				    table1.setHeaderVisible(true);
				    table1.addSelectionListener(new SelectionAdapter() {
				    	public void widgetSelected(SelectionEvent evt) {
				    		table1WidgetSelected(evt);
				    	}
				    });
				}
				{
					lblPro = new Label(cptPro, SWT.NONE);
					lblPro.setText("项目");
					lblPro.setBounds(10, 18, 53, 22);
				}
				{
					cboPro = new Combo(cptPro, SWT.READ_ONLY);
					cboPro.setBounds(76, 18, 215, 23);
					cboPro.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							cboProWidgetSelected(evt);
						}
					});
				}
				{
					FormData fd_cptPwdModify = new FormData();
					fd_cptPwdModify.width = 520;
					fd_cptPwdModify.height = 510;
					fd_cptPwdModify.left =  new FormAttachment(216, 1000, 0);
					fd_cptPwdModify.top =  new FormAttachment(-8, 1000, 0);
					fd_cptPwdModify.bottom =  new FormAttachment(1000, 1000, 0);
					fd_cptPwdModify.right =  new FormAttachment(1000, 1000, 0);
					cptPwdModify = new Composite(this, SWT.NONE);
					cptPwdModify.setLayout(null);
					cptPwdModify.setLayoutData(fd_cptPwdModify);
					
					composite1Group = new Group(cptPwdModify,SWT.NONE);
					composite1Group.setBounds(30, 35, 444, 369);
					composite1Group.setText("密码修改");
					
					{
						lblOldPwd = new Label(composite1Group, SWT.NONE);
						lblOldPwd.setText("请输入原密码：");
						lblOldPwd.setBounds(55, 65, 136, 23);
					}
					{
						lblNewPwd = new Label(composite1Group, SWT.NONE);
						lblNewPwd.setText("请输入新密码：");
						lblNewPwd.setBounds(55, 130, 130, 24);
					}
					{
						txtOldPwd = new Text(composite1Group, SWT.PASSWORD|SWT.BORDER);
						txtOldPwd.setBounds(215, 65, 182, 24);
					}
					{
						txtNewPwd = new Text(composite1Group, SWT.PASSWORD|SWT.BORDER);
						txtNewPwd.setBounds(215, 130, 182, 24);
					}
					{
						lblNewPwd2 = new Label(composite1Group, SWT.NONE);
						lblNewPwd2.setText("请再次输入新密码：");
						lblNewPwd2.setBounds(55, 200, 122, 25);
					}
					{
						txtNewPwd2 = new Text(composite1Group, SWT.PASSWORD|SWT.BORDER);
						txtNewPwd2.setBounds(215, 200, 182, 25);
					}
					{
						btnSubmitPwd = new Button(composite1Group, SWT.PUSH | SWT.CENTER);
						btnSubmitPwd.setText("确定");
						btnSubmitPwd.setBounds(125, 290, 85, 30);
						btnSubmitPwd.addSelectionListener(new SelectionAdapter() {
							public void widgetSelected(SelectionEvent evt) {
								btnSubmitPwdWidgetSelected(evt);
							}
						});
					}
					{
						btnResetPwd = new Button(composite1Group, SWT.PUSH | SWT.CENTER);
						btnResetPwd.setText("重置");
						btnResetPwd.setBounds(285, 290, 85, 30);
						btnResetPwd.addSelectionListener(new SelectionAdapter() {
							public void widgetSelected(SelectionEvent evt) {
								txtOldPwd.setText("");
								txtNewPwd.setText("");
								txtNewPwd2.setText("");
							}
						});
					}
				}
				{
					FormData tree1LData = new FormData();
					tree1LData.width = 126;
					tree1LData.height = 488;
					tree1LData.left =  new FormAttachment(0, 1000, 0);
					tree1LData.top =  new FormAttachment(0, 1000, 0);
					tree1LData.bottom =  new FormAttachment(1000, 1000, 0);
					tree1LData.right =  new FormAttachment(216, 1000, 0);
					tree1 = new Tree(this, SWT.NONE);
					tree1.setLayoutData(tree1LData);
					tree1.addListener(SWT.MouseDown, new Listener() {
						public void handleEvent(Event event) {
							Point point = new Point(event.x, event.y);
							TreeItem item = tree1.getItem(point);
							if (item != null)
								tree1WidgetSelected(event, item);
						}
					});
				}
				{
					treeItem1 = new TreeItem(tree1, SWT.NONE);
					treeItem1.setText("功能菜单");
					{
						treeItem11 = new TreeItem(treeItem1, SWT.NONE);
						treeItem11.setText("缺陷信息管理");
						{
							treeItem111 = new TreeItem(treeItem11, SWT.NONE);
							treeItem111.setText("缺陷报告");
						}
						{
							treeItem112 = new TreeItem(treeItem11, SWT.NONE);
							treeItem112.setText("缺陷处理");
						}
						{
							treeItem113 = new TreeItem(treeItem11, SWT.NONE);
							treeItem113.setText("缺陷查询");
						}
					}
					{
						treeItem12 = new TreeItem(treeItem1, SWT.NONE);
						treeItem12.setText("个人信息管理");
						{
							treeItem121 = new TreeItem(treeItem12, SWT.NONE);
							treeItem121.setText("密码修改");
						}
					}
					{
						treeItem2 = new TreeItem(treeItem1, SWT.NONE);
						treeItem2.setText("退出系统");
					}

				}
				this.layout();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private void tree1WidgetSelected(Event evt,TreeItem item) {
		try{
			if(item.getText().equals("功能菜单")){
				TreeVisible(2);
				InitProjectByUserId();
				InitBugByProject();
				lblBugId.setVisible(false);
				lblSubmit.setVisible(false);
				lblTime.setVisible(false);
				txtBugId.setVisible(false);
				txtSubmit.setVisible(false);
				txtTime.setVisible(false);
			}else if(item.getText().equals("缺陷信息管理")){
				TreeVisible(2);
			}else if(item.getText().equals("个人信息管理")){
				TreeVisible(1);
			}else if(item.getText().equals("缺陷报告")){
				TreeVisible(3);
				InitCreateBug();
				ClearAllAddBugReport();
				cboAssignReview.setEnabled(true);
				cboClose.setEnabled(false);
				btnAssignReview.setSelection(true);
				btnClose.setSelection(false);
			}else if(item.getText().equals("缺陷处理")){
				TreeVisible(2);
				InitProjectByUserId();
				InitBugByProject();
				btnSaveBug.setEnabled(true);
				btnSubmitBug.setEnabled(true);
				lblBugId.setVisible(false);
				lblSubmit.setVisible(false);
				lblTime.setVisible(false);
				txtBugId.setVisible(false);
				txtSubmit.setVisible(false);
				txtTime.setVisible(false);
			}else if(item.getText().equals("缺陷查询")){
				EMQuery.userType = "1";
				EMQuery.userName = CommonUser.userName;
				EMQuery.showGUI();
			}else if(item.getText().equals("密码修改")){
				TreeVisible(1);
			}else if(item.getText().equals("退出系统")){
			    box1.setMessage("确定要退出吗？");
			    if(box1.open() == SWT.NO)
			    	return;
			    shell.close();
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}

	private void TreeVisible(int count){
		boolean check[] = new boolean[4];
		for(int i = 0; i < 4; i++)
			if(count == i)
				check[i] = true;
			else
				check[i] = false;
		this.cptPwdModify.setVisible(check[1]);
		this.cptPwdModify.setEnabled(check[1]);
		this.cptPro.setVisible(check[2]);
		this.cptPro.setEnabled(check[2]);
		this.composite3.setVisible(check[3]);
		this.composite3.setEnabled(check[3]);
	}

	private void btnSubmitPwdWidgetSelected(SelectionEvent evt) {
		if (txtNewPwd.getText().trim().equals("")) {
			box.setMessage("密码不能为空！");
			box.open();
			return;
		}
		if (!txtNewPwd.getText().trim().equals(txtNewPwd2.getText().trim())) {
			box.setMessage("您两次输入的新密码不一致！");
			box.open();
			return;
		}

		if (Util.isValidPassword(txtNewPwd.getText().trim()) == false) {
			box.setMessage("新密码格式有误，只能由数字和字母组成，长度为为6-12位！");
			box.open();
			return;
		}
		try {
			ArrayList<Object> out = new ArrayList<Object>();
			out.add(userName);
			out.add(txtOldPwd.getText());
			out.add(this.txtNewPwd.getText());
			SocketConnection.setCmd("modifypwd");
			SocketConnection.setListOut(out);
			SocketConnection.DataTransmission();
			
			if (SocketConnection.getListIn() == null || SocketConnection.getListIn().size() == 0)
			{
				box.setMessage("服务器连接出错，请检查配置文件和网络连接！");
				box.open();
				//return;
				System.exit(0);
			}
			
			String tag = SocketConnection.getListIn().get(0).toString();
			if(tag.equals("1")){ //修改成功
				box.setMessage("密码修改成功!");
				box.open();
				txtOldPwd.setText("");
				txtNewPwd.setText("");
				txtNewPwd2.setText("");
				return;
			}else if(tag.equals("-1")){
				box.setMessage("您输入的原密码不正确！");
				box.open();
				return;
			}else{
				box.setMessage("密码修改失败!");
				box.open();
				return;
			}
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	private void table1WidgetSelected(SelectionEvent evt) {
		if (table1.getSelection() != null && table1.getSelection().length > 0)
		{
			try{
			    EMProcess.ebmsID = table1.getSelection()[0].getText(1);
				if (EMProcess.ebmsID == null || EMProcess.ebmsID.trim().length() == 0)
					return;			
				EMProcess.userType = "1";
				EMProcess.userName = CommonUser.userName;
				//EMProcess.ebmsID = table1.getSelection()[0].getText(1).substring(1);
				EMProcess.days = table1.getSelection()[0].getText(5);
				EMProcess.responpeo = table1.getSelection()[0].getText(2);
				EMProcess.status = Util.convertToStatusId(table1.getSelection()[0].getText(3));
				EMProcess.wtgyms = table1.getSelection()[0].getText(4);
				EMProcess.proID = getProjectByUserIdProjectId.get(Util.findIdByStr(cboPro.getText(),getProjectByUserIdProjectName));
				EMProcess.isEdit = "true";
				EMProcess.showGUI();
			}catch(Exception ex){
				ex.printStackTrace();
			}
		}
	}
	
	private void ClearAllAddBugReport(){
		txtBugId.setText("D****");
		txtSubmit.setText(userName);
		txtTime.setText("xxxx-xx-xx");
		txtHard.setText("");
		txtSoft.setText("");
		txtBugSummary.setText("");
		txtAttach.setText("");			
		txtBugDetail.setText("");
		txtRecurStep.setText("");
		cboRecur.select(0);
		cboSeverity.select(0);
		
		btnSaveBug.setEnabled(true);
		btnSubmitBug.setEnabled(true);
		txtRecurStep.setEditable(true);
	
			
	}
	
	private void InitCreateBug(){//创建缺陷报告单,初始化页面
		//初始化项目列表
		try {
			addBugReportProjectId.clear();
			addBugReportProjectName.clear();
			SocketConnection.setCmd("getprojectbyuserid");
			ArrayList<Object> out = new ArrayList<Object>();
			out.add(userName);
			SocketConnection.setListOut(out);
			SocketConnection.DataTransmission();
			
			if (SocketConnection.getListIn() == null || SocketConnection.getListIn().size() == 0)
			{
				box.setMessage("服务器连接出错，请检查配置文件和网络连接！");
				box.open();
				//return;
				System.exit(0);
			}
			
			ArrayList<Object> in = SocketConnection.getListIn();
			if(in.get(0).toString().equals("-1")){
				String items[] ={"无项目"};
				cboProId.setItems(items);
				cboProId.select(0);
			} else{
				int count = in.size()/2;
				String items[] = new String[count];
				for(int i = 0;i < count; i++){
					addBugReportProjectId.add(in.get(2*i).toString());
					addBugReportProjectName.add(in.get(2*i+1).toString());
					items[i] = in.get(2*i).toString();
				}
				cboProId.setItems(items);
				cboProId.select(0);
			}
			showModelAddBug(cboProId.getText());
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		//时间,人
		try {
			txtSubmit.setText(userName);
			txtTime.setText("xxxx-xx-xx");
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	private void showModelAddBug(String proid){//添加报告单，模块
		try {
			addBugReportUserName.clear();
			addBugReportUserId.clear();
			if(cboProId.getText().equals("无项目"))
				return;
			SocketConnection.setCmd("getprojectdetailinfo");
			ArrayList<Object> out = new ArrayList<Object>();
			out.add(proid);
			SocketConnection.setListOut(out);
			SocketConnection.DataTransmission();
			if (SocketConnection.getListIn() == null || SocketConnection.getListIn().size() == 0)
			{
				box.setMessage("服务器连接出错，请检查配置文件和网络连接！");
				box.open();
				//return;
				System.exit(0);
			}
			
			ArrayList<Object> in = SocketConnection.getListIn();
			//显示项目所有信息
			//cboProVersion.setText(in.get(1).toString()); //version
			String[] versions = {in.get(1).toString()};
			cboProVersion.setItems(versions);
			cboProVersion.select(0);
			
			int modelNum = Integer.parseInt(in.get(2).toString());
			String []items = null;
			if(modelNum != 0){
				items = new String[modelNum];
				for(int i = 0; i < modelNum; i++)
					items[i] = in.get(i + 3).toString();
				cboSubsys.setItems(items);
				cboSubsys.select(0);
			}else
				cboSubsys.removeAll();
			int userNum = Integer.parseInt(in.get(modelNum + 3).toString());
			String []userItems = null;
			if(userNum != 0){
				userItems = new String[userNum];
				for(int i = 0; i < userNum; i++){
					addBugReportUserId.add(in.get(modelNum + 4 + 2*i).toString());
					addBugReportUserName.add(in.get(modelNum + 4 + 2*i + 1).toString());
					//userItems[i] = in.get(modelNum + 4 + 2*i + 1).toString();
					userItems[i] = in.get(modelNum + 4 + 2*i + 1).toString()+"("
					                +in.get(modelNum + 4 + 2*i).toString()+")";
				}
				cboAssignReview.removeAll();
				cboAssignReview.setItems(userItems);
				cboAssignReview.select(0);
			}else
				cboAssignReview.removeAll();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	private void InitProjectByUserId(){//通过userid找到和他相关的项目
		try {
			getProjectByUserIdProjectId.clear();
			getProjectByUserIdProjectName.clear();
			table1.removeAll();
			SocketConnection.setCmd("getprojectbyuserid");
			ArrayList<Object> out = new ArrayList<Object>();
			out.add(userName);
			SocketConnection.setListOut(out);
			SocketConnection.DataTransmission();
			if (SocketConnection.getListIn() == null || SocketConnection.getListIn().size() == 0)
			{
				box.setMessage("服务器连接出错，请检查配置文件和网络连接！");
				box.open();
				//return;
				System.exit(0);
			}
			
			ArrayList<Object> in = SocketConnection.getListIn();
			if(in.get(0).toString().equals("-1")){
				String[] items = {"无项目"};
				cboPro.setItems(items);
				cboPro.select(0);
				return;
			}
			String []items = new String[in.size()/2];
			for(int i = 0; i < in.size()/2; i++){
				getProjectByUserIdProjectId.add(in.get(2*i).toString());
				getProjectByUserIdProjectName.add(in.get(2*i+1).toString());
				items[i] = in.get(2*i+1).toString();
			}
			cboPro.setItems(items);
			cboPro.select(0);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	private void InitBugByProject(){
		try {
			table1.removeAll();
			if(cboPro.getText().equals("无项目"))
				return;
			SocketConnection.setCmd("getbugbyprojectid");
			ArrayList<Object> out = new ArrayList<Object>();
			out.add(getProjectByUserIdProjectId.get(Util.findIdByStr(cboPro.getText(),getProjectByUserIdProjectName)));
			out.add(userName);
			SocketConnection.setListOut(out);
			SocketConnection.DataTransmission();
			if (SocketConnection.getListIn() == null || SocketConnection.getListIn().size() == 0)
			{
				box.setMessage("服务器连接出错，请检查配置文件和网络连接！");
				box.open();
				//return;
				System.exit(0);
			}
			
			ArrayList<Object> in = SocketConnection.getListIn();
			for(int i=0;i<in.size();i++)
				System.out.println(in.get(i));
		
			Color color = new Color(display,new RGB(222,226,226));
			if(in.get(0).toString().equals("-1")){
				TableItem item = new TableItem(table1, SWT.NONE);
				item.setText(new String[]{"","","无缺陷报告","","",""});
				item.setBackground(color);
				return;
			}
			int bugNum = in.size()/6;
		    for(int i = 0; i < bugNum; i++){
		    	TableItem item = new TableItem(table1, SWT.NONE);
		    	item.setText(new String[] {
		    			String.valueOf(i), 
		    			//"D" + in.get(i*6).toString(), 
		    			in.get(i*6).toString(), 
		    			in.get(i*6+2).toString(),
		    			Util.convertToStatusName(in.get(i*6+3).toString()),
		    			in.get(i*6+4).toString(),
		    			in.get(i*6+5).toString()});
		    	if(i%2 == 0)
		    		item.setBackground(color);
		    }
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	private void cboProWidgetSelected(SelectionEvent evt) {
		InitBugByProject();
	}
	
	private void submitBug()
	{
		
		ArrayList<Object> out = new ArrayList<Object>();
		String bidStr = txtBugId.getText().trim();
		String pidStr = cboProId.getText().trim();
		int start;
		for(start = 0; start < bidStr.length(); start++)
		{
			if (bidStr.charAt(start) != '0')
				break;
		}
		if (start >= bidStr.length())
			return;
		bidStr = bidStr.substring(start);
		out.add(pidStr);
		out.add(bidStr);
		SocketConnection.setListOut(out);
		try {
			SocketConnection.DataTransmission();
			if (SocketConnection.getListIn() == null || SocketConnection.getListIn().size() == 0)
			{
				box.setMessage("服务器连接出错，请检查配置文件和网络连接！");
				box.open();
				//return;
				System.exit(0);
			}
			
		} catch (IOException e) {
			e.printStackTrace();
			box.setMessage("提交失败!");
			box.open();
			return;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			box.setMessage("提交失败!");
			box.open();
			return;
		}
		ArrayList<Object> in = SocketConnection.getListIn();
		if(in == null || in.get(0) == null || in.get(0).toString().equals("-1")){
			box.setMessage("提交失败!");
			box.open();
		}else{
			box.setMessage("操作成功!");
			box.open();
			
		}
		
	}
	
	private void newBug(){//创建缺陷报告单
		ArrayList<Object> out = new ArrayList<Object>();
		try {				
			
			out.add(cboProId.getItem(cboProId.getSelectionIndex()));//proid
			out.add(txtBugId.getText().substring(1));
			out.add(userName);//person
			Date date = new Date();
			Format formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//设置格式    
			txtTime.setText(formatter.format(date).substring(0, 10));
			out.add(formatter.format(date));//time
			out.add(cboSubsys.getItem(cboSubsys.getSelectionIndex()));//model name
			
			if (txtHard.getText().trim().equals("")) {
				box.setMessage("硬件环境不能为空");
				box.open();
				return;
			} else
				out.add(txtHard.getText());
			
			if (txtSoft.getText().trim().equals("")) {
				box.setMessage("软件环境不能为空");
				box.open();
				return;
			} else
				out.add(txtSoft.getText());
			
			out.add(cboSeverity.getSelectionIndex());
			
			if (txtBugSummary.getText().trim().equals(""))// 概要描述
			{
				box.setMessage("缺陷概要描述不能为空");
				box.open();
				return;
			} else
				out.add(txtBugSummary.getText());
			
			if (txtBugDetail.getText().trim().equals("")) {
				box.setMessage("缺陷详细描述不能为空");
				box.open();
				return;
			} else
				out.add(txtBugDetail.getText());
			
			out.add(cboRecur.getSelectionIndex());
			
			if (cboRecur.getSelectionIndex()==0&&txtRecurStep.getText().trim().equals("")) {
				box.setMessage("重现步骤不能为空");
				box.open();
				return;
			} else
				out.add(txtRecurStep.getText());
			
			if(txtAttach.getText().equals(""))
				out.add(" ");
			else
				out.add(txtAttach.getText());
			
			
			if(btnAssignReview.getSelection()){ //不关闭
				out.add("next");
				/*out.add(addBugReportUserId.get(
							Util.findIdByStr(
									cboAssignReview.getItem(
											cboAssignReview.getSelectionIndex()
									),
									addBugReportUserName
								)
							)
						);*/
				out.add(Util.splitUserNameId(cboAssignReview.getItem(cboAssignReview.getSelectionIndex()))[1]);
				
			}
			else{
				out.add("shutdown");
				out.add(cboClose.getSelectionIndex() + 6);
			}
			for(int i=0;i<out.size();i++)
				System.out.println(out.get(i));
			SocketConnection.setListOut(out);
			SocketConnection.DataTransmission();
			if (SocketConnection.getListIn() == null || SocketConnection.getListIn().size() == 0)
			{
				box.setMessage("服务器连接出错，请检查配置文件和网络连接！");
				box.open();
				//return;
				System.exit(0);
			}
			
			ArrayList<Object> in = SocketConnection.getListIn();
			if(in.get(0).toString().equals("-1")){
				box.setMessage("添加失败!");
				box.open();
				return;
			}else{
				box.setMessage("操作成功!");
				box.open();
				//txtBugId.setText("D" + in.get(0).toString());
				txtBugId.setText(in.get(0).toString());
				lblBugId.setVisible(true);
				lblSubmit.setVisible(true);
				lblTime.setVisible(true);
				txtBugId.setVisible(true);
				txtSubmit.setVisible(true);
				txtTime.setVisible(true);
			}
		} 
		catch (IOException e) {
			e.printStackTrace();
		} 
		catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		
	}
	
	private void btnSaveBugWidgetSelected(SelectionEvent evt) {//创建缺陷报告单 ，保存
		SocketConnection.setCmd("newbugsave");
		newBug();
	}

	private void btnSubmitBugWidgetSelected(SelectionEvent evt) {//创建缺陷报告单，提交
		if(txtBugId.getText() == null || txtBugId.getText().trim() == null || txtBugId.getText().trim().length()==0)
		{
			SocketConnection.setCmd("draftbugsubmit");
			submitBug();
		}
		else
		{
			SocketConnection.setCmd("newbugsubmit");
			newBug();
		}
		
		
		ClearAllAddBugReport();
		
	}
	
	private void cboProIdWidgetSelected(SelectionEvent evt) {// 创建缺陷报告单，项目ID列表
		showModelAddBug(cboProId.getItem(cboProId.getSelectionIndex()));
	}
}
